package spring.concurrency.executor;

import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import spring.concurrency.executor.task.CallableTask;

public class Main2 {

	public static void main(String[] args) {
		ScheduledThreadPoolExecutor executor=(ScheduledThreadPoolExecutor)
				Executors.newScheduledThreadPool(1);
		System.out.printf("Main: Starting at: %s\n",new Date());
		for (int i = 0; i < 5; i++) {
			CallableTask task = new CallableTask("Task " + i);
			executor.schedule(task, i + 10, TimeUnit.SECONDS);
		}
	    
	    executor.shutdown();
	    try {
	        executor.awaitTermination(1, TimeUnit.DAYS);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	    System.out.printf("Main: Ends at: %s\n",new Date());

	}

}
